<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<title>修改密码--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/static/plugin/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/static/css/public.css" media="all" />
	<script type="text/javascript" src="/static/plugin/jquery/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="/static/plugin/layui/layui.js" ></script>
	<script type="text/javascript" src="/static/js/base.js"></script>
</head>
<body class="childrenBody">
<div id="app">
	<form class="layui-form" action="">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<div class="layui-input-block layui-red pwdTips" style="color: red">新密码必须两次输入一致才能提交</div>
			<div class="layui-form-item">
				<label class="layui-form-label">用户名</label>
				<div class="layui-input-block">
					<input type="hidden" id="userId" th:value="${user.userId}">
					<input type="text" id="realName" th:value="${user.realName}"  disabled class="layui-input layui-disabled">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">旧密码</label>
				<div class="layui-input-block">
					<input type="password" id="oldPad" placeholder="请输入旧密码" lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码</label>
				<div class="layui-input-block">
					<input type="password" id="newPad"  placeholder="请输入新密码" lay-verify="required"  class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认密码</label>
				<div class="layui-input-block">
					<input type="password" id="conNewPad" placeholder="请确认密码" lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" id="subBtn" lay-submit lay-filter="addForm">立即修改</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</div>
	</form>
</div>
<script>
	layui.use(['table','layer','upload','form','laydate'], function() {
		var table = layui.table;
		var form = layui.form;
		var layer = layui.layer;
		var laydate = layui.laydate;


		form.on("submit(addForm)",function() {
			var newPad = document.getElementById('newPad').value;
			var conNewPad = document.getElementById('conNewPad').value;
			var oldPad = document.getElementById('oldPad').value;
			var userId = document.getElementById('userId').value;
			if (newPad != conNewPad) {
				layer.msg("两次密码不一致",{icon:2})
				return false;
			}
			$.ajax({
				type: 'get',
				data:{'userId':userId,'oldPad':oldPad,'newPad':newPad},
				url: '/user/changeUserPaw',
				success:function (result) {
					if (result == 0) {
						layer.msg("密码不正确",{icon:2})
					}else if (result == 1){
						layer.msg('修改成功',{icon:1})
						setTimeout(function(){
							location.reload();
						},1000);
					}else if (result == 3){
						layer.msg("新密码旧密码相同",{icon:2})
					}
				}
			});
			return false;
		});

	});

</script>
</body>
</html>